package adpater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a513.R;

import java.util.ArrayList;
import java.util.List;

import entity.Animation;

public class AnimationAdapterGrid extends BaseAdapter {
    private Context context;
    private List<Animation> list = new ArrayList<>();
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.grid_item,null);
             holder = new Holder();
            holder.desc = convertView.findViewById(R.id.desc_grid);
            holder.img = convertView.findViewById(R.id.grid_img);
            holder.title = convertView.findViewById(R.id.tv_title);
            convertView.setTag(holder);
        }else{
            holder =  (Holder) convertView.getTag();
        }
        Animation animation = list.get(position);
        holder.title.setText(animation.getTitle());
        holder.desc.setText(animation.getDescription());
        holder.img .setImageResource(animation.getPic());

        return convertView;
    }

    public AnimationAdapterGrid(Context context, List<Animation> list) {
        this.context = context;
        this.list = list;
    }
    public final class Holder{
        public ImageView img;
        public TextView title;
        public TextView desc;
    }
}
